#include <iostream>
#include <map>
using namespace std;

// 50.67 %
class Solution
{
  public:
	bool isAnagram(string s, string t)
	{
		map<char, int> myMap;
		for (int i = 0; i < s.size(); i++)
		{
			myMap[s[i]]++;
		}
		for (int i = 0; i < t.size(); i++)
		{
			if (myMap[t[i]] > 0)
			{
				myMap[t[i]]--;
			}
			else
			{
				return false;
			}
		}
		map<char, int>::iterator iter;
		iter = myMap.begin();
		while (iter != myMap.end())
		{
			if (iter->second != 0)
				return false;
			iter++;
		}
		return true;
	}
};

int main()
{
	string s = "anagram", t = "nagaram";
	cout << Solution().isAnagram(s, t) << endl;
	return 0;
}
